<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="java.sql.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>COLD EYES</title>
<style>
#center-img2 {
	background-color: white;
	width: 80%;
	height: 100%;
	float: left;
}

input {
	font-family: '나눔고딕';
	font-size: 11px
}

a:link {
	text-decoration: none;
	color: #000000;
}

a:visited {
	text-decoration: none;
}

a:active {
	text-decoration: none;
}

#pos {
	font-family: '나눔고딕';
	font-size: 11px;
	width: 800px;
	height: 570px;
	border: 1px solid #aaaaaa;
	float: right;
	href = 
}
</style>


</head>
<body>


		<div id='center-img2'>

			<%
					Class.forName("oracle.jdbc.driver.OracleDriver");

					String url = "jdbc:oracle:thin:@127.0.0.1:1521:xe";
					String db_user = "hr";
					String db_pwd = "hr";

					int total = 0;
					int page_num = 0;

					try {

						Connection conn = DriverManager.getConnection(url, db_user,
								db_pwd);

						String sql = "select count(*) from board";
						PreparedStatement pstmt = conn.prepareStatement(sql);
						ResultSet rs = pstmt.executeQuery();

						if (rs.next())
							total = rs.getInt(1); // 데베에 저장된 테이블 로우 수 반환 

						for (int i = 1; i <= total; i += 10)
							page_num++;

						sql = "select no, id, title, write_date, count from board where no between ? and ? order by no desc";
						pstmt = conn.prepareStatement(sql);

						int front = total - 9;
						pstmt.setInt(1, front);
						pstmt.setInt(2, total);

						rs = pstmt.executeQuery();
				%>

			<!-- 구분 테이블 -->
			<div align='center'>
				<div id='pos' align='center'>
					<table cellpadding="0" cellspacing="0" border="0" align='center'>

						<!-- <tr height='50'>
					<td></td>
				</tr> -->

						<tr>
							<td colspan=5 align='center'><font
								style="font-family: 'Roboto Cn'; font-size: 40px; color: #ac013f">
									<b> ::: JAVA BOARD ::: </b>
							</font></td>
						</tr>
						<tr height='20'>
							<td colspan=5 align='center'>총 게시물 : <%=total%>개
							</td>
						</tr>

						<tr height='50'>
							<td></td>
						</tr>

						<!-- 웹페이지 탑부분과 여백을 둠 -->

						<tr align='center'>
							<!-- 			<td width="5"><img src="img/table_left.gif" width="5"
				height="30" /></td> -->
							<td width='70'>번호</td>
							<td width='300'>제목</td>
							<td width='100'>작성자</td>
							<td width='200'>작성일</td>
							<td width='70'>조회수</td>
							<!-- 			<td width="7"><img src="img/table_right.gif" width="5"
				height="30" /></td> -->
						</tr>

						<tr height="10" align="center">
						</tr>
						<tr height="1" bgcolor="#D2D2D2">
							<td colspan="6"></td>
						</tr>
						<tr height="1" bgcolor="#82B5DF">
							<td colspan="6"></td>
						</tr>

						<%
								if (total == 0) { // 테이블에 저장된 데이터가 아무것도 없다면
							%>

						<tr align="center" bgcolor="#FFFFFF" height="30">
							<td colspan="6">등록된 글이 없습니다.</td>
						</tr>

						<%
								} else {
										while (rs.next()) {
											int num = rs.getInt("no");
											String name = rs.getString("id");
											String title = rs.getString("title");
											String time = rs.getString("write_date");
											int count = rs.getInt("count");
											//}
											//}
							%>

						<tr height="25" align='center'>
							<td><%=num%></td>
							<td><a href="read.jsp?idx=<%=num%>&read=1"><%=title%></a></td>
							<td><%=name%></td>
							<td><%=time%></td>
							<td><%=count%></td>
						</tr>

						<tr height="10" align="center">
						</tr>
						<tr height="1" bgcolor="#D2D2D2">
							<td colspan="6"></td>
						</tr>

						<%
								}
									}
									rs.close();
									pstmt.close();
									conn.close();
								} catch (SQLException e) {
									out.println(e.toString());
								}
							%>
						<tr height="1" bgcolor="#82B5DF">
							<td colspan="6"></td>
						</tr>
					</table>

					<!-- 구분 버튼 -->

					<table width="100%" cellpadding="0" cellspacing="0" border="0">
						<tr align="right" height="50">
							<td><input type=button value="글쓰기"
								OnClick="href='worksMain.jsp?works_list=worksWrite.jsp?total=<%=total%>'"></td>
						</tr>

						<tr height="1" bgcolor="#82B5DF">
							<td></td>
						</tr>

						<tr height='10'>
							<td></td>
						</tr>
					</table>

					<table>
						<tr>
							<%
									for (int i = 1; i <= page_num; i++) {
								%>
							<td width='15'><a
								href='list_copy.jsp?idx=<%=i%>&total=<%=total%>'><%=i%></a></td>
							<%
						}
					%>
						</tr>
					</table>
				</div>
			</div>

		</div>
	
</body>
</html>